﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace App8._11
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        DrawingVisual _hexagramDrawing = null;

        public Window1()
        {
            InitializeComponent();
            
	        Title = "Visual Window";
	        Width = 300;
	        Height = 200;
	        _hexagramDrawing = new DrawingVisual();

            Pen pen = new Pen(new SolidColorBrush(Colors.Bisque), 2);
            LinearGradientBrush brush = new LinearGradientBrush();
            brush.StartPoint = new Point(0, 0);
            brush.EndPoint = new Point(1, 1);
            GradientStop stop1 = new GradientStop(Colors.AliceBlue, 0);
            GradientStop stop2 = new GradientStop(Colors.GreenYellow, 1);
            brush.GradientStops.Add(stop1);
            brush.GradientStops.Add(stop2);

            using (DrawingContext context = _hexagramDrawing.RenderOpen())
            {
                context.DrawGeometry(brush, pen, Geometry.Parse(
                    "F 0 M 0,50 L 75,6.7 L 75,93.3 Z M 100,50 L 25,6.7 L 25,93.3 Z"));
            }

            if (_hexagramDrawing != null)
            {
                AddVisualChild(_hexagramDrawing);
                AddLogicalChild(_hexagramDrawing);
            }
        }

        protected override int VisualChildrenCount
        {
            get
            {
                if (_hexagramDrawing != null)
                    return 1;
	            else
	                return 0;
            }
        }

        protected override Visual GetVisualChild(int index)
        {
            if (index != 0 && VisualChildrenCount != 0)
                throw new ArgumentOutOfRangeException("index");

            return _hexagramDrawing;
        }
    }
}
